define(function(require) {

    require('../../../c/base/index');

    require('../../../c/nav/index');

    var User = require('./mods/white-user');


    var shopTable;
    var firstTime = true;
    var totalCount = 0;

    var Config = {
        init: function() {
            //初始化菜单选中效果
            $(".fa-circle-o").each(function() {
                if ($(this).parents("a").text() == "店铺查询") {
                    $(this).parents("a").parents("li").addClass("active");
                }
            });
            this.initShopTable();
            this.initValidator();
            this.initDatas();
            this.initDatetimepicker();
            this.bindXiaoerInfo();
            this.initUpload();
            this.bindEvent();
            User.init();
            //this.doSearch();
            //默认取urlParam参数
            var shopId = CRM.getUrlParam("id");
            if (shopId) {
                $("#shop_id").val(shopId);
                this.doSearch();
            }
        },
        /**
         * 执行查询操作.
         */
        doSearch: function() {
            if ($("#shop_id").val()) {
                $("#J_Search").data('bootstrapValidator').validate();
                if ($("#J_Search").data('bootstrapValidator').isValid()) {
                    $('#shop_table').DataTable().ajax.reload();
                }
            } else if ($("#shop_name").val()) {
                $('#shop_table').DataTable().ajax.reload();
            } else if ($("#shop_xiaoer_mobile").val()) {
                $('#shop_table').DataTable().ajax.reload();
            } else if ($("#shop_owner_mobile").val()) {
                $('#shop_table').DataTable().ajax.reload();
            } else {
                $("#msg_dialog_content").text("输入内容不能为空！");
                $('#msg_dialog').modal('show');
            }
        },
        /**
         * 初始化店铺的列表
         */
        initShopTable: function() {
            var self = this;
            shopTable = $("#shop_table").dataTable({
                "oLanguage": CRM.pageConfig,
                "sScrollX": "100%", //表格的宽度
                "sScrollXInner": "100%", //表格的内容宽度
                "bScrollCollapse": true, //当显示的数据不足以支撑表格的默认的高度时，依然显示纵向的滚动条。(默认是false)
                "bPaginate": true, //是否显示分页
                "bLengthChange": true, //每页显示的记录数
                "bFilter": false, //搜索栏
                "bSort": false, //是否支持排序功能
                "bInfo": true, //显示表格信息
                "bAutoWidth": false, //自适应宽度
                "bServerSide": true, //开启服务端处理
                "sAjaxSource": CRM.getOuterUrl('/shop/shop/queryShopByName'),
                "fnInitComplete": function() {
                    this.fnAdjustColumnSizing(true);
                },
                "fnServerData": function(sSource, aoData, fnCallback) {
                    if (firstTime) {
                        firstTime = false;
                        return;
                    }
                    var _url = CRM.getOuterUrl('/shop/shop/queryShopByName');
                    var dataString = JSON.stringify({
                        "shopName": $("#shop_name").val(),
                        "operator": $.cookie('_uk'),
                        "pageBegin": aoData[3].value / aoData[4].value + 1,
                        "pageSize": aoData[4].value
                    });
                    if ($("#shop_id").val()) { //通过ID查询
                        _url = CRM.getOuterUrl('/shop/shop/queryShopById');
                        dataString = JSON.stringify({
                            "id": $("#shop_id").val(),
                            "operator": $.cookie('_uk')
                        });
                    } else if ($("#shop_xiaoer_mobile").val()) {
                        _url = CRM.getOuterUrl('/shop/shop/queryShopByXiaoerId');
                        var _xiaoerId = self.getUserInfo($("#shop_xiaoer_mobile").val());
                        if (!_xiaoerId) {
                            CRM.showDialog("号码不存在");
                            return;
                        }
                        dataString = JSON.stringify({
                            "xiaoerId": _xiaoerId,
                            "operator": $.cookie('_uk'),
                            "pageBegin": 1,
                            "pageSize": 999
                        });
                    } else if ($("#shop_owner_mobile").val()) {
                        _url = CRM.getOuterUrl('/shop/shop/queryShopByUserId');
                        var _userId = self.getUserInfo($("#shop_owner_mobile").val());
                        if (!_userId) {
                            CRM.showDialog("号码不存在");
                            return;
                        }
                        dataString = JSON.stringify({
                            "userId": _userId,
                            "operator": $.cookie('_uk'),
                            "pageBegin": 1,
                            "pageSize": 999
                        });
                    }
                    $.ajax({
                        "type": 'POST',
                        "url": _url,
                        "dataType": "json",
                        contentType: "application/json",
                        xhrFields: {
                            withCredentials: true
                        },
                        "data": dataString,
                        contentType: "application/json",
                        "success": function(req) {
                            if (req.responseCode && req.status) {
                                var resultData = CRM.getDataTabelDtaObject();
                                if (req.entry) {
                                    if (($("#shop_id").val() || $("#shop_owner_mobile").val()) && !$("#shop_xiaoer_mobile").val()) { //通过ID查询
                                        resultData.iTotalDisplayRecords = 1;
                                        resultData.iTotalRecords = 1;

                                        resultData.aaData.push([
                                            req.entry.id,
                                            CRM.htmlEncode(req.entry.shopName),
                                            CRM.htmlEncode(req.entry.city),
                                            CRM.htmlEncode(req.entry.ownerName),
                                            (CRM.htmlEncode(req.entry.xiaoerName) + " " + req.entry.xiaoerMobile),
                                            CRM.htmlEncode(req.entry.statusDesc),
                                            CRM.htmlEncode(req.entry.typeDesc),
                                            req.entry.isBalance,
                                            CRM.htmlEncode(req.entry.tagsDesc),
                                            req.entry
                                        ]);
                                    } else {
                                        if ($("#shop_xiaoer_mobile").val()) {
                                            resultData.iTotalDisplayRecords = req.entry.length;
                                            resultData.iTotalRecords = totalCount;
                                        } else {
                                            self.queryShopByNameCount();
                                            resultData.iTotalDisplayRecords = totalCount;
                                            resultData.iTotalRecords = totalCount;
                                        }
                                        for (var length in req.entry) {
                                            resultData.aaData.push([
                                                req.entry[length].id,
                                                CRM.htmlEncode(req.entry[length].shopName),
                                                CRM.htmlEncode(req.entry[length].city),
                                                CRM.htmlEncode(req.entry[length].ownerName),
                                                CRM.htmlEncode(req.entry[length].xiaoerName),
                                                CRM.htmlEncode(req.entry[length].statusDesc),
                                                CRM.htmlEncode(req.entry[length].typeDesc),
                                                req.entry[length].isBalance,
                                                CRM.htmlEncode(req.entry[length].tagsDesc),
                                                req.entry[length]
                                            ]);
                                        }
                                    }
                                }
                            } else {
                                $("#msg_dialog_content").text(req.message);
                                $('#msg_dialog').modal('show');
                            }
                            fnCallback(resultData);
                        },
                        error: function(e) {
                            //请求出错处理
                            $("#msg_dialog_content").text("获取店铺列表,请求服务异常！");
                            $('#msg_dialog').modal('show');
                        }
                    });
                },
                "aaSorting": [
                    [1, "asc"]
                ], //给列表排序 ，第一个参数表示数组 (由0开始)。1 表示Browser列。第二个参数为 desc或是asc
                "aoColumns": [{
                        "bSortable": true
                    }, {
                        "bSortable": true
                    }, {
                        "bSortable": true
                    }, {
                        "bSortable": true
                    }, {
                        "bSortable": true
                    }, {
                        "bSortable": true
                    }, {
                        "bSortable": true
                    }, {
                        "bSortable": true,
                        "mRender": function(data, type, row) {
                            var html = "未知";
                            if (data == "1") {
                                html = "结算";
                            } else {
                                html = "不结算";
                            }

                            return html;
                        }
                    }, {
                        "bSortable": true
                    }, {
                        "bSortable": false,
                        "mRender": function(data) {
                            var id = data.id,
                                type = data.type;
                            var itemUrl = self.getItemUrl(id);
                            var html = '<div class="dropdown">';
                            html += '<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu_' + id + '" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">';
                            html += '更多操作<span class="caret"></span>';
                            html += '</button>';
                            html += '<ul class="dropdown-menu" aria-labelledby="dropdownMenu_' + id + '">';
                            html += "<li><a target='itme' href='" + itemUrl + "'>商品管理</a></li>";
                            html += "<li><a href='javascript:modifyShop(\"" + id + "\")'>店铺信息修改</a></li>";
                            html += "<li><a href='javascript:shopSuspension(\"" + id + "\")'>店铺下线</a></li>";
                            var onsellStr = "暂停营业";
                            if (data.onsell != 1) {
                                onsellStr = "恢复营业";
                            }
                            html += "<li><a href='javascript:shopPauseOrOnSale(\"" + id + "\",\"" + data.onsell + "\")'>" + onsellStr + "</a></li>";
                            html += "<li><a href='javascript:auditShop(\"" + id + "\")'>审核店铺信息</a></li>";
                            //html += "<li><a target='_blank' href='" + getOuterUrl('/buyer/crm/php/o2o/seller/shop/seller_shop_alipay_modify.php?page=new-app-page&shop_id=' + data) + "'>支付宝账号修改</a></li>";
                            //html += "<li><a target='_blank' href='" + getOuterUrl('/buyer/crm/php/o2o/seller/shop/icbc.php?page=new-app-page&shop_id=' + data) + "'>中国工商银行账号设置</a></li>";
                            html += "<li><a target='_blank' href='" + CRM.getOuterUrl('/rockland/home.do?shop_id=' + id) + "'>修改配送范围</a></li>";
                            if (data.couponSwitch == 1) {
                                html += "<li><a href='javascript:shopCouponSwitch(\"" + id + "\",0);'>店铺红包权限打开</a></li>";
                            } else {
                                html += "<li><a href='javascript:shopCouponSwitch(\"" + id + "\",1);'>店铺红包权限关闭</a></li>";
                            }

                            html += "<li><a href='javascript:editShop(\"" + id + "\");'>店铺店主更换</a></li>";
                            html += "<li><a href='javascript:deleteShop(\"" + id + "\");'>店铺删除</a></li>";
                            html += "<li><a href='javascript:queryOrders("+id+",\""+data.shopName+"\");'>店铺订单</a></li>";

                            if (type == 6) {
                                html += "<li><a href='javascript:modifyShopSale(\"" + id + "\")'>店铺投放修改</a></li>";
                                html += '<li><a class="J_White" data-id=' + id + ' href="javascript:void(0)">黑名单管理</a></li>';
                            }
                            html += '</ul></div>';
                            return html;
                        }
                    }

                ], //列设置，表有几列，数组就有几项
                "bStateSave": true, //保存状态到cookie *************** 很重要 ， 当搜索的时候页面一刷新会导致搜索的消失。使用这个属性就可避免了
                "sPaginationType": "full_numbers" //分页，一共两种样式，full_numbers和two_button(默认)

            });
        },
        /**
         * 根据店铺名查询店铺数量
         */
        queryShopByNameCount: function() {
            $.ajax({
                "type": 'POST',
                "url": CRM.getOuterUrl('/shop/shop/queryShopByNameCount'),
                "dataType": "json",
                async: false, //请求是否异步，默认为异步，这也是ajax重要特性
                contentType: "application/json",
                xhrFields: {
                    withCredentials: true
                },
                "data": JSON.stringify({
                    "shopName": $("#shop_name").val(),
                    "operator": $.cookie('_uk')
                }),
                contentType: "application/json",
                "success": function(req) {
                    if (req.responseCode && req.status) {
                        totalCount = req.entry;
                    } else {
                        $("#msg_dialog_content").text(req.message);
                        $('#msg_dialog').modal('show');
                    }
                },
                error: function(e) {
                    //请求出错处理
                    $("#msg_dialog_content").text("根据店铺名查询店铺数量,请求服务异常！");
                    $('#msg_dialog').modal('show');
                }
            });
        },
        /**
         * 店铺店主更换
         * @param shopId
         */
        editShop: function(shopId) {
            var self = this;
            $.ajax({
                "type": 'POST',
                "url": CRM.getOuterUrl('/shop/shop/queryShopById'),
                "dataType": "json",
                async: true, //请求是否异步，默认为异步，这也是ajax重要特性
                contentType: "application/json",
                xhrFields: {
                    withCredentials: true
                },
                "data": JSON.stringify({
                    "id": shopId,
                    "operator": $.cookie('_uk')
                }),
                contentType: "application/json",
                "success": function(req) {
                    if (req.responseCode && req.status) {
                        if (req.entry) {
                            $("#shopId").val(shopId);
                            $("#ownerName").val(req.entry.ownerName);
                            $("#ownerSocialId").val(req.entry.ownerSocialId);
                            self.getUserById(req.entry.userId);
                            $("#newOwnerName").val("");
                            $("#newOwnerSocialId").val("");
                            $("#newUserMobile").val("");
                            $('#shop_edit_dialog').modal('show');
                            $('#shop_edit_dialog').on('shown.bs.modal', function(e) {
                                $("#change_form").data('bootstrapValidator').resetForm();
                            });
                        }
                    } else {
                        $("#msg_dialog_content").text(req.message);
                        $('#msg_dialog').modal('show');
                    }
                },
                error: function(e) {
                    //请求出错处理
                    $("#msg_dialog_content").text("查询店铺信息,请求服务异常！");
                    $('#msg_dialog').modal('show');
                }
            });
        },
        /**
         * 删除店铺
         * @param shopId
         */
        deleteShop: function(shopId) {
            var self = this;
            $('#comfirm').unbind("click");
            $("#comfirm").on('click', function() {
                $('#confirm_dialog').modal('hide');
                $.ajax({
                    "type": 'POST',
                    "url": CRM.getOuterUrl('/shop/shop/deleteShop'),
                    "dataType": "json",
                    async: true, //请求是否异步，默认为异步，这也是ajax重要特性
                    contentType: "application/json",
                    xhrFields: {
                        withCredentials: true
                    },
                    "data": JSON.stringify({
                        id: shopId,
                        operator: $.cookie('_uk')
                    }),
                    contentType: "application/json",
                    "success": function(req) {
                        $("#msg_dialog_content").text(req.message);
                        $('#msg_dialog').modal('show');
                        $('#shop_table').DataTable().ajax.reload();
                    },
                    error: function(e) {
                        //请求出错处理
                        $("#msg_dialog_content").text("删除店铺,请求服务异常！");
                        $('#msg_dialog').modal('show');
                    }
                });
            });
            $("#confirm_dialog_content").text("确定要删除这个店铺？该操作不能恢复！");
            $('#confirm_dialog').modal('show');
        },
        queryOrders:function(shopId,shopName){
            window.open('../order/orderQuery.html?shopId=' + shopId + '&shopName=' + shopName);
        },
        /**
         * 红包权限操作
         * @param shopId
         */
        shopCouponSwitch: function(shopId, couponSwitch) {
            var self = this;
            $('#comfirm').unbind("click");
            $("#comfirm").on('click', function() {
                $('#confirm_dialog').modal('hide');
                $.ajax({
                    "type": 'POST',
                    "url": CRM.getOuterUrl('/shop/shop/shopCouponSwitch'),
                    "dataType": "json",
                    async: true, //请求是否异步，默认为异步，这也是ajax重要特性
                    contentType: "application/json",
                    xhrFields: {
                        withCredentials: true
                    },
                    "data": JSON.stringify({
                        id: shopId,
                        closeCoupon: couponSwitch,
                        closeReason: $("#closeReason").val(),
                        operator: $.cookie('_uk')
                    }),
                    contentType: "application/json",
                    "success": function(req) {
                        $("#msg_dialog_content").text(req.message);
                        $('#msg_dialog').modal('show');
                        $('#shop_table').DataTable().ajax.reload();
                    },
                    error: function(e) {
                        //请求出错处理
                        $("#msg_dialog_content").text("红包权限操作,请求服务异常！");
                        $('#msg_dialog').modal('show');
                    }
                });
            });
            $("#confirm_dialog_content").html("");
            if (couponSwitch == 1) {

                var _html = '<textarea id="closeReason" name="closeReason" rows="5" cols="30" placeholder="请填写关闭的原因"></textarea>';
                $("#confirm_dialog_content").html(_html);
            } else {
                $("#confirm_dialog_content").text("确定开放红包?");
            }
            $('#confirm_dialog').modal('show');
        },
        /**
         * 店铺店主更换
         */
        changeShopOwner: function() {
            $("#change_form").data('bootstrapValidator').validate();
            if ($("#change_form").data('bootstrapValidator').isValid()) {
                $.ajax({
                    "type": 'POST',
                    "url": CRM.getOuterUrl('/shop/shop/changeShopOwner'),
                    "dataType": "json",
                    async: true, //请求是否异步，默认为异步，这也是ajax重要特性
                    contentType: "application/json",
                    xhrFields: {
                        withCredentials: true
                    },
                    "data": JSON.stringify({
                        "shopId": $("#shopId").val(),
                        "ownerName": $("#ownerName").val(),
                        "ownerSocialId": $("#ownerSocialId").val(),
                        "userMobile": $("#userMobile").val(),
                        "newOwnerName": $("#newOwnerName").val(),
                        "newOwnerSocialId": $("#newOwnerSocialId").val(),
                        "newUserMobile": $("#newUserMobile").val(),
                        "operator": $.cookie('_uk')
                    }),
                    contentType: "application/json",
                    "success": function(req) {
                        $("#msg_dialog_content").text(req.message);
                        $('#msg_dialog').modal('show');
                    },
                    error: function(e) {
                        //请求出错处理
                        $("#msg_dialog_content").text("店铺店主更换,请求服务异常！");
                        $('#msg_dialog').modal('show');
                    }
                });
            }
        },
        /**
         * 表单验证初始化
         */
        initValidator: function() {
            $('#J_Search').bootstrapValidator({
                message: '输入错误',
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    shop_id: {
                        message: 'error',
                        validators: {
                            regexp: {
                                regexp: /^[0-9]+$/,
                                message: '请输入数字'
                            }
                        }
                    },
                    shop_xiaoer_mobile: {
                        message: 'error',
                        validators: {
                            phone: {
                                country: 'CN',
                                message: '请输入正确的电话格式'
                            }
                        }
                    },
                    shop_owner_mobile: {
                        message: 'error',
                        validators: {
                            phone: {
                                country: 'CN',
                                message: '请输入正确的电话格式'
                            }
                        }
                    }
                }
            });
            $('#change_form').bootstrapValidator({
                message: '输入错误',
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    userMobile: {
                        message: '店主电话输入错误',
                        validators: {
                            notEmpty: {
                                message: '店主电话不能为空'
                            }
                        }
                    },
                    newOwnerName: {
                        validators: {
                            message: '新店主名字输入错误',
                            notEmpty: {
                                message: '新店主名字不能为空'
                            }
                        }
                    },
                    newOwnerSocialId: {
                        validators: {
                            message: '新店主身份证输入错误',
                            notEmpty: {
                                message: '新店主身份证不能为空'
                            }
                        }
                    },
                    newUserMobile: {
                        validators: {
                            message: '新店主电话输入错误',
                            notEmpty: {
                                message: '新店主电话不能为空'
                            },
                            phone: {
                                country: 'CN',
                                message: '请输入正确的电话格式'
                            }
                        }
                    },
                    ownerSocialId: {
                        validators: {
                            message: '店主身份证输入错误',
                            notEmpty: {
                                message: '店主身份证不能为空,请先补全店主信息'
                            }
                        }
                    }
                }
            });

            $('#modify_form').bootstrapValidator({
                message: '输入错误',
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    modify_shopName: {
                        message: '店铺名称输入错误',
                        validators: {
                            notEmpty: {
                                message: '店铺名称不能为空'
                            },
                            stringLength: {
                                message: '请输入1-64位的店铺名称',
                                min: 1,
                                max: 64
                            }
                        }
                    },
                    modify_dayStartTime: {
                        message: '开业时间输入错误',
                        validators: {
                            notEmpty: {
                                message: '开业时间不能为空'
                            }
                        }
                    },
                    modify_dayEndTime: {
                        message: '打烊时间输入错误',
                        validators: {
                            notEmpty: {
                                message: '打烊时间不能为空'
                            }
                        }
                    },
                    modify_address: {
                        message: '店铺地址输入错误',
                        validators: {
                            notEmpty: {
                                message: '店铺地址不能为空'
                            },
                            stringLength: {
                                message: '请输入1-128位的店铺地址',
                                min: 1,
                                max: 128
                            }
                        }
                    },
                    modify_leastSendAmount: {
                        message: '店铺起送金额输入错误',
                        validators: {
                            notEmpty: {
                                message: '店铺起送金额不能为空'
                            },
                            numeric: {
                                message: '请输入有效的数字'
                            }
                        }
                    },
                    modify_shopWeight: {
                        message: '店铺权重输入错误',
                        validators: {
                            numeric: {
                                message: '请输入有效的数字'
                            }
                        }
                    }
                }
            });

            $('#sale_form').bootstrapValidator({
                message: '输入错误',
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    sale_pic_url_1: {
                        message: '图片1链接地址错误',
                        validators: {
                            uri: {
                                message: '请输入正确的URL'
                            },
                            callback: {
                                message: '图片1与图片1路径两者都需要填写或者都清空',
                                callback: function(value, validator) {
                                    if ($("#sale_pic_img_1").attr("src") || value) {
                                        if (!$("#sale_pic_img_1").attr("src") || !value) {
                                            return false;
                                        }
                                    }
                                    return true;
                                }
                            }
                        }
                    },
                    sale_pic_url_2: {
                        message: '图片1链接地址错误',
                        validators: {
                            uri: {
                                message: '请输入正确的URL'
                            },
                            callback: {
                                message: '图片2与图片2路径两者都需要填写或者都清空',
                                callback: function(value, validator) {
                                    if ($("#sale_pic_img_2").attr("src") || value) {
                                        if (!$("#sale_pic_img_2").attr("src") || !value) {
                                            return false;
                                        }
                                    }
                                    return true;
                                }
                            }
                        }
                    },
                    sale_pic_url_3: {
                        message: '图片1链接地址错误',
                        validators: {
                            uri: {
                                message: '请输入正确的URL'
                            },
                            callback: {
                                message: '图片3与图片3路径两者都需要填写或者都清空',
                                callback: function(value, validator) {
                                    if ($("#sale_pic_img_3").attr("src") || value) {
                                        if (!$("#sale_pic_img_3").attr("src") || !value) {
                                            return false;
                                        }
                                    }
                                    return true;
                                }
                            }
                        }
                    },
                    sale_pic_url_4: {
                        message: '图片1链接地址错误',
                        validators: {
                            uri: {
                                message: '请输入正确的URL'
                            },
                            callback: {
                                message: '图片4与图片4路径两者都需要填写或者都清空',
                                callback: function(value, validator) {
                                    if ($("#sale_pic_img_4").attr("src") || value) {
                                        if (!$("#sale_pic_img_4").attr("src") || !value) {
                                            return false;
                                        }
                                    }
                                    return true;
                                }
                            }
                        }
                    },
                    sale_pic_url_5: {
                        message: '图片1链接地址错误',
                        validators: {
                            uri: {
                                message: '请输入正确的URL'
                            },
                            callback: {
                                message: '图片5与图片5路径两者都需要填写或者都清空',
                                callback: function(value, validator) {
                                    if ($("#sale_pic_img_5").attr("src") || value) {
                                        if (!$("#sale_pic_img_5").attr("src") || !value) {
                                            return false;
                                        }
                                    }
                                    return true;
                                }
                            }
                        }
                    }
                }
            });
        },
        /**
         * 根据用户ID获取用户信息
         * @param usserId
         */
        getUserById: function(usserId) {
            var returnObject;
            $.ajax({
                "type": 'GET',
                "url": CRM.getOuterUrl('/member/getUserbyUserId.do?userId=' + usserId),
                "dataType": "json",
                async: false, //请求是否异步，默认为异步，这也是ajax重要特性
                contentType: "application/json",
                xhrFields: {
                    withCredentials: true
                },
                contentType: "application/json",
                "success": function(req) {
                    if (req.responseCode == 0 && req.status) {
                        if (req.entry) {
                            $("#userMobile").val(req.entry.mobile);
                            returnObject = req.entry;
                        }
                    } else {
                        $("#msg_dialog_content").text(req.message);
                        $('#msg_dialog').modal('show');
                    }
                },
                error: function(e) {
                    //请求出错处理
                    $("#msg_dialog_content").text("根据用户ID获取用户信息,请求服务异常！");
                    $('#msg_dialog').modal('show');
                }
            });
            return returnObject;
        },
        /**
         * 获得商品维护界面
         */
        getItemUrl: function(shopId) {
            return CRM.getOuterUrl('/itemcenter/crm/item/list?itemStatus=0,10,20,30,40,100&shopId=' + shopId);
        },
        /**
         * 初始化下拉清单的数据
         */
        initDatas: function() {
            this.initShopType();
            this.initShopTages();
            this.initCities();
            this.initCommission();
        },
        /**
         * 修改店铺信息
         */
        modifyShop: function(shopId) {
            var self = this;
            $.ajax({
                "type": 'POST',
                "url": CRM.getOuterUrl('/shop/shop/queryShopById'),
                "dataType": "json",
                async: true, //请求是否异步，默认为异步，这也是ajax重要特性
                contentType: "application/json",
                xhrFields: {
                    withCredentials: true
                },
                "data": JSON.stringify({
                    "id": shopId,
                    "operator": $.cookie('_uk')
                }),
                contentType: "application/json",
                "success": function(req) {
                    if (req.responseCode && req.status) {
                        if (req.entry) {
                            self.setShopValues(req.entry);
                            if (req.entry.status == 0 || req.entry.status == 30) {
                                $("#modifyShop").hide();
                                $("#push_modify").show();
                                $("#push_audit").show();
                            } else if (req.entry.status == 40) {
                                $("#modifyShop").hide();
                                $("#push_modify").hide();
                                $("#push_audit").hide();
                            } else {
                                $("#modifyShop").show();
                                $("#push_modify").hide();
                                $("#push_audit").hide();
                            }
                            $("#pass").hide();
                            $("#not_pass").hide();

                            //保存店铺状态
                            self.shopStatus = req.entry.status;
                            $('#shop_modify_dialog').modal('show');
                            $('#shop_modify_dialog').on('shown.bs.modal', function(e) {
                                $("#modify_form").data('bootstrapValidator').resetForm();
                            });
                        }
                    } else {
                        $("#msg_dialog_content").text(req.message);
                        $('#msg_dialog').modal('show');
                    }
                },
                error: function(e) {
                    //请求出错处理
                    $("#msg_dialog_content").text("查询店铺信息,请求服务异常！");
                    $('#msg_dialog').modal('show');
                }
            });
        },
        /**
         * 修改投放信息
         * @param shopId
         */
        modifyShopSale: function(shopId) {
            var self = this;
            CRM.clearForm("sale_form");
            $("img[id^='sale_pic_img']").attr("src", "")
            CRM.request({
                "type": 'POST',
                "url": CRM.getOuterUrl('/shop/shop/queryShopById'),
                "dataType": "json",
                contentType: "application/json",
                "data": JSON.stringify({
                    id: shopId,
                    operator: $.cookie('_uk')
                }),
                "success": function(req) {
                    if (req.status) {
                        if (req.entry) {
                            $("#sale_shop_id").val(shopId);
                            if (req.entry.banner) {
                                var _banners = req.entry.banner.split("@!;");
                                $.each(_banners, function(_index, _banner) {
                                    $("#sale_pic_img_" + (_index + 1)).attr("src", _banner.split("@!:")[0]);
                                    $("#sale_pic_url_" + (_index + 1)).val(_banner.split("@!:")[1]);
                                });
                            }
                            $("#shop_sale_dialog").modal('show');
                            $('#shop_sale_dialog').on('shown.bs.modal', function(e) {
                                $("#sale_form").data('bootstrapValidator').resetForm();
                            });
                        }
                    } else {
                        CRM.showDialog(req.message);
                    }
                }
            });
        },
        /**
         * 审核店铺
         * @param shopId
         */
        auditShop: function(shopId) {
            var self = this;
            $.ajax({
                "type": 'POST',
                "url": CRM.getOuterUrl('/shop/shop/queryShopById'),
                "dataType": "json",
                async: true, //请求是否异步，默认为异步，这也是ajax重要特性
                contentType: "application/json",
                xhrFields: {
                    withCredentials: true
                },
                "data": JSON.stringify({
                    "id": shopId,
                    "operator": $.cookie('_uk')
                }),
                contentType: "application/json",
                "success": function(req) {
                    if (req.responseCode && req.status) {
                        if (req.entry) {
                            self.setShopValues(req.entry);
                            $('#shop_modify_dialog').modal('show');
                            $('#shop_modify_dialog').on('shown.bs.modal', function(e) {
                                $("#modify_form").data('bootstrapValidator').resetForm();
                            });
                            if (req.entry.status == 40) {
                                $("#pass").hide();
                                $("#not_pass").hide();
                            } else {
                                $("#pass").show();
                                $("#not_pass").show();
                            }
                            $("#push_audit").hide();
                            $("#push_modify").hide();
                            $("#modifyShop").hide();
                        }
                    } else {
                        $("#msg_dialog_content").text(req.message);
                        $('#msg_dialog').modal('show');
                    }
                },
                error: function(e) {
                    //请求出错处理
                    $("#msg_dialog_content").text("查询店铺信息,请求服务异常！");
                    $('#msg_dialog').modal('show');
                }
            });
        },
        /**
         * 设置查询出来的值
         * @param data
         */
        setShopValues: function(data) {
            var self = this;
            $(':input', '#modify_form')
                .not(':button, :submit, :reset')
                .val('')
                .removeAttr('checked')
                .removeAttr('selected'); //清空form
            $("[id^=img]").attr("src", "");
            $("#modify_shopId").val(data.id);
            $("#modify_shopName").val(data.shopName);
            $("#modify_shopType").val(data.type);
            $("#modify_isBalance").val(data.isBalance);
            $("#modify_tags").val(data.tags);
            self._tags = $("#modify_tags").find("option:selected").text();
            if (data.tagsDesc != "超市" && data.tagsDesc != "烟酒") { //超市和烟酒需要烟酒许可
                $("#fieldset_yc").hide();
                $("#fieldset_jl").hide();
            } else {
                $("#fieldset_yc").show();
                $("#fieldset_jl").show();
            }
            $("#modify_dayStartTime").val(data.dayStartTime);
            $("#modify_dayStartTime_view").val(data.dayStartTime);
            $("#modify_dayEndTime_view").val(data.dayEndTime);
            $("#modify_dayEndTime").val(data.dayEndTime);
            $("#modify_createXiaoer").val(data.createXiaoerName + " " + data.createXiaoerMobile);
            $("#modify_xiaoer").val(data.xiaoerName + " " + data.xiaoerMobile);
            $("#modify_xiaoerId").val(data.xiaoerId);
            $("#modify_city").val(data.city);
            $("#modify_address").val(data.address);
            $("#modify_deliveryAreaRadius").val(data.deliveryAreaRadius);
            $("#modify_leastSendAmount").val(data.leastSendAmount / 100);
            $("#modify_onlinePayOnly").val(data.onlinePayOnly);
            $("#modify_ownername").val(data.ownerName);
            $("#modify_userId").val(data.userId);
            $("#modify_ownerSocialId").val(data.ownerSocialId);
            $("#modify_socialImage").attr("src", getUrlImg() + data.socialImage);
            $("#modify_socialImageBack").attr("src", getUrlImg() + data.socialImageBack);
            $("#modify_shopWeight").val(data.shopWeight);
            $("#modify_shopFranchiseDesc").val(data.updateShopFranchise);
            var userInfo = self.getUserById($.cookie('_uk'));
            $("#card_field").hide();
            $("#zhifubao_field").hide();
            $("#modify_xiaoer").attr("readonly", "readonly");
            $("#modify_ownername").attr("readonly", "readonly");
            $("#modify_shopWeight").attr("readonly", "readonly");
            if (parseInt(userInfo.level) >= 700) {
                $("#modify_xiaoer").removeAttr("readonly");
                $("#modify_ownername").removeAttr("readonly");
                $("#modify_shopWeight").removeAttr("readonly");
                self.queryShopReceiptsAccount(data.id, 1);
                $("#card_field").show();
                $("#zhifubao_field").show();

            }
            //判断是否审核通过过
            if (data.auditeFirst) {
                $('#modify_shopType').attr("disabled", "disabled");
                $('#modify_isBalance').attr("disabled", "disabled");
            } else {
                $('#modify_shopType').removeAttr("disabled");
                $('#modify_isBalance').removeAttr("disabled");
            }
            if(data.tryLocation.indexOf("franchise")!=-1){
                $('#form_shopFranchise').css("display","inherit");
            }else{
                $('#form_shopFranchise').css("display","none");
            }
            self.queryShopBusiLicence(data.id);
        },
        /**
         * 店铺类型数据初始化
         */
        initShopType: function() {
            $.ajax({
                "type": 'POST',
                "url": CRM.getOuterUrl('/shop/shopUtil/queryShopType'),
                "dataType": "json",
                async: true, //请求是否异步，默认为异步，这也是ajax重要特性
                contentType: "application/json",
                xhrFields: {
                    withCredentials: true
                },
                "data": JSON.stringify({}),
                contentType: "application/json",
                "success": function(req) {
                    if (req.responseCode && req.status) {
                        if (req.entry) {
                            $("#modify_shopType").html("");
                            for (var length in req.entry) {
                                $("#modify_shopType").append("<option value='" + length + "'>" + req.entry[length] + "</option>");
                            }

                        }
                    } else {
                        $("#msg_dialog_content").text(req.message);
                        $('#msg_dialog').modal('show');
                    }
                },
                error: function(e) {
                    //请求出错处理
                    $("#msg_dialog_content").text("查询店铺类型信息,请求服务异常！");
                    $('#msg_dialog').modal('show');
                }
            });
        },
        /**
         * 经营范围数据初始化
         */
        initShopTages: function() {
            $.ajax({
                "type": 'POST',
                "url": CRM.getOuterUrl('/shop/shopUtil/queryShopTags'),
                "dataType": "json",
                async: true, //请求是否异步，默认为异步，这也是ajax重要特性
                contentType: "application/json",
                xhrFields: {
                    withCredentials: true
                },
                "data": JSON.stringify({}),
                contentType: "application/json",
                "success": function(req) {
                    if (req.responseCode && req.status) {
                        if (req.entry) {
                            $("#modify_tags").html("");
                            for (var length in req.entry) {
                                $("#modify_tags").append("<option value='" + length + "'>" + req.entry[length] + "</option>");
                            }
                        }
                    } else {
                        $("#msg_dialog_content").text(req.message);
                        $('#msg_dialog').modal('show');
                    }
                },
                error: function(e) {
                    //请求出错处理
                    $("#msg_dialog_content").text("查询经营范围信息,请求服务异常！");
                    $('#msg_dialog').modal('show');
                }
            });
        },
        /**
         * 初始化日期控件
         */
        initDatetimepicker: function() {
            $(".form_time").datetimepicker({
                language: 'zh-CN',
                weekStart: 1,
                todayBtn: 1,
                autoclose: 1,
                todayHighlight: 1,
                startView: 1,
                minView: 0,
                maxView: 1,
                forceParse: 0
            });
            $('.form_date').datetimepicker({
                language: 'zh-CN',
                weekStart: 1,
                todayBtn: 1,
                autoclose: 1,
                todayHighlight: 1,
                startView: 2,
                minView: 2,
                forceParse: 0
            });
        },
        /**
         * 小二信息查询
         */
        bindXiaoerInfo: function() {
            $('#modify_xiaoer').typeahead({
                onSelect: function(item) {
                    $("#modify_xiaoerId").val(item.value);
                },
                ajax: {
                    url: CRM.getOuterUrl("/dataapi/user/search.do?minlevel=300&start=0&count=100"),
                    displayField: "dis",
                    valueField: "valId",
                    triggerLength: 1,
                    items: 100,
                    method: "get",
                    loadingClass: "loading-circle",
                    preDispatch: function(query) {
                        return {
                            mobile: query,
                            name: query
                        }
                    },
                    preProcess: function(data) {
                        if (data.success === false) {
                            return false;
                        }
                        var docs = data.docs;
                        if (!docs || docs.length == 0) {
                            return false;
                        }
                        for (var j in docs) {
                            var doc = docs[j];
                            doc.dis = doc.mobile + ' ' + doc.realName;
                            doc.valId = doc.userId;
                        }
                        return docs;
                    }
                }
            });
        },
        /**
         * 城市下拉初始化
         */
        initCities: function() {
            $.ajax({
                url: CRM.getOuterUrl('/shop/city/queryOpenCity'),
                contentType: "application/json",
                dataType: "json", //返回格式为json
                async: true, //请求是否异步，默认为异步，这也是ajax重要特性
                data: JSON.stringify({}), //参数值
                type: "POST", //请求方式
                xhrFields: {
                    withCredentials: true
                },
                success: function(req) {
                    //请求成功时处理登录
                    if (req.status == false && req.responseCode == 10212) {
                        var loc = location.href;
                        location.href = CRM.getOuterUrl('/member/login.html?redirectUrl=' + encodeURIComponent(loc));
                    } else if (req.responseCode && req.status) {
                        if (req.entry) {
                            $("#modify_city").html("");
                            for (var length in req.entry) {
                                $("#modify_city").append("<option value='" + req.entry[length].city + "'>" + req.entry[length].city + "</option>");
                            }
                        }
                    } else {
                        $("#msg_dialog_content").text(req.message);
                        $('#msg_dialog').modal('show');
                    }
                },
                error: function(e) {
                    //请求出错处理
                    $("#msg_dialog_content").text("查询城市信息,请求服务异常！");
                    $('#msg_dialog').modal('show');
                }
            });
        },
        /**
         * 店铺加盟类型下拉初始化
         */
        initCommission: function () {
            $.ajax({
                url: CRM.getOuterUrl('/shop/shopUtil/queryShopUtilEnum'),
                contentType: "application/json",
                dataType: "json",   //返回格式为json
                async: true, //请求是否异步，默认为异步，这也是ajax重要特性
                data: JSON.stringify({}),   //参数值
                type: "POST",   //请求方式
                xhrFields: {
                    withCredentials: true
                },
                success: function (req) {
                    if (req.responseCode && req.status) {
                        if (req.entry) {
                            $("#modify_shopFranchiseDesc").html("");
                            var commission = req.entry.commission;
                            for (var length in commission) {
                                $("#modify_shopFranchiseDesc").append("<option value='" + length +"' "+(commission[length]=="不收佣金"?"disabled":"")+">" + commission[length] + "</option>");
                            }
                        }
                    } else {
                        $("#msg_dialog_content").text(req.message);
                        $('#msg_dialog').modal('show');
                    }
                },
                error: function (e) {
                    //请求出错处理
                    $("#msg_dialog_content").text("查询加盟类型,请求服务异常！");
                    $('#msg_dialog').modal('show');
                }
            });
        },
        /**
         * 查询店铺营业执照
         */
        queryShopBusiLicence: function(shopId) {
            var self = this;
            $.ajax({
                "type": 'POST',
                "url": CRM.getOuterUrl('/shop/licence/queryShopBusiLicence'),
                "dataType": "json",
                async: true, //请求是否异步，默认为异步，这也是ajax重要特性
                contentType: "application/json",
                xhrFields: {
                    withCredentials: true
                },
                "data": JSON.stringify({
                    "shopId": shopId,
                    "operator": $.cookie('_uk')
                }),
                contentType: "application/json",
                "success": function(req) {
                    if (req.responseCode && req.status) {
                        if (req.entry) {
                            self.setShopBusiLicenceValues(req.entry);
                        }
                    } else {
                        $("#msg_dialog_content").text(req.message);
                        $('#msg_dialog').modal('show');
                    }
                },
                error: function(e) {
                    //请求出错处理
                    $("#msg_dialog_content").text("查询店铺营业执照,请求服务异常！");
                    $('#msg_dialog').modal('show');
                }
            });
        },
        /**
         * 设置执照的值
         * @param data
         */
        setShopBusiLicenceValues: function(data) {
            for (var length in data) {
                var _objectId = "";
                if (data[length].type == "1") { //工商营业执照
                    _objectId = "";
                } else if (data[length].type == "2") { //食品流通许可证
                    _objectId = "_sp";
                } else if (data[length].type == "3") { //卫生许可证
                    _objectId = "_ws";
                } else if (data[length].type == "4") { //烟草许可证
                    _objectId = "_yc";
                } else if (data[length].type == "5") { //酒类许可证
                    _objectId = "_jl";
                }
                $("#modify_legalPerson" + _objectId).val((data[length].legalPerson));
                $("#modify_busiLicenceNo" + _objectId).val((data[length].busiLicenceNo));
                $("#modify_expDate" + _objectId + "_view").val(data[length].expDate);
                $("#modify_expDate" + _objectId).val(data[length].expDate);
                $("#modify_id" + _objectId).val(data[length].id);
                if (data[length].busiLicencePic && data[length].busiLicencePic != "null") {
                    $("#img" + _objectId).attr("src", getUrlImg() + data[length].busiLicencePic);
                } else {
                    $("#img" + _objectId).attr("src", "");
                }
            }
        },

        /**
         * 提交修改
         */
        doUpdate: function(isSubmitToAudit) {
            var self = this;
            //判断工商营业执照
            if ($("#img").attr("src") == "") {
                CRM.showDialog("请先上传工商营业执照！");
                return;
            }
            var tags = $("#modify_tags").find("option:selected").text();
            if (tags != self._tags) {
                var str = '[' + self._tags + ' >>> ' + tags + ']修改店铺类型将解绑所有小区，是否修改 ?'
                if (!confirm(str)) {
                    return false;
                }
            }

            $("#modify_form").data('bootstrapValidator').validate();
            if ($("#modify_form").data('bootstrapValidator').isValid()) {
                var formValue = {
                    Id: $("#modify_shopId").val(),
                    shopName: $("#modify_shopName").val(),
                    operator: $.cookie('_uk'),
                    address: $("#modify_address").val(),
                    dayStartTime: $("#modify_dayStartTime").val(),
                    dayEndTime: $("#modify_dayEndTime").val(),
                    xiaoerId: $("#modify_xiaoerId").val(),
                    onlinePayOnly: $("#modify_onlinePayOnly").val(),
                    leastSendAmount: $("#modify_leastSendAmount").val() * 100,
                    deliveryAreaRadius: $("#modify_deliveryAreaRadius").val(),
                    ownerName: $("#modify_ownername").val(),
                    tags: $("#modify_tags").val(),
                    socialImage: $("#modify_socialImage").attr("src").replace(getUrlImg(), ""),
                    socialImageBack: $("#modify_socialImageBack").attr("src").replace(getUrlImg(), ""),
                    ownerSocialId: $('#modify_ownerSocialId').val(),
                    shopWeight: $("#modify_shopWeight").val(),
                    shopFranchise: $("#modify_shopFranchiseDesc").find("option:selected").val()
                }
                $.ajax({
                    "type": 'POST',
                    "url": CRM.getOuterUrl('/shop/shop/updateShopForXiaoer'),
                    "dataType": "json",
                    async: true, //请求是否异步，默认为异步，这也是ajax重要特性
                    contentType: "application/json",
                    xhrFields: {
                        withCredentials: true
                    },
                    "data": JSON.stringify(formValue),
                    contentType: "application/json",
                    "success": function(req) {
                        if (req.status) {
                            if (self.shopStatus == 0 || self.shopStatus == 30) {
                                $("#push_audit").show();
                                $("#push_modify").show();
                                $("#pass").hide();
                                $("#not_pass").hide();
                            } else {
                                $("#push_modify").hide();
                                $("#push_modify").hide();
                                $("#pass").show();
                                $("#not_pass").show();
                            }
                            $("#modifyShop").hide();
                            $('#shop_table').DataTable().ajax.reload();
                            //提交审核
                            if (isSubmitToAudit) {
                                self.submitToAudit();
                            }
                        }else{
                            CRM.showDialog(req.message);
                        }
                    },
                    error: function(e) {
                        //请求出错处理
                        CRM.showDialog("更新店铺信息,请求服务异常！");
                    }
                });
                self.doUpdateBusiLicence();
            }
        },
        /**
         * 新店铺调用审核接口
         */
        submitToAudit: function() {
            //判断工商营业执照
            if ($("#img").attr("src") == "") {
                CRM.showDialog("请先上传工商营业执照！");
                return;
            }
            $.ajax({
                "type": 'POST',
                "url": CRM.getOuterUrl('/shop/shop/submitToAudit_CRM'),
                "dataType": "json",
                async: true, //请求是否异步，默认为异步，这也是ajax重要特性
                contentType: "application/json",
                xhrFields: {
                    withCredentials: true
                },
                "data": JSON.stringify({
                    "id": $("#modify_shopId").val()
                }),
                contentType: "application/json",
                "success": function(req) {
                    if (req.status) {
                        $("#modifyShop").hide();
                        $("#push_modify").hide();
                        $("#push_audit").hide();
                        $("#pass").show();
                        $("#not_pass").show();
                    }
                    $('#shop_table').DataTable().ajax.reload();
                    CRM.showDialog(req.message);
                },
                error: function(e) {
                    //请求出错处理
                    CRM.showDialog("更新店铺信息,请求服务异常！");
                }
            });
        },
        /**
         * 生成营业执照对象
         * @param type
         * @param _objectId
         * @returns {{}}
         */
        getBusiLicenceObj: function(type, _objectId) {
            var busiLicence = {};
            busiLicence.id = $("#modify_id" + _objectId).val();
            busiLicence.type = type;
            busiLicence.legalPerson = $("#modify_legalPerson" + _objectId).val();
            busiLicence.busiLicenceNo = $("#modify_busiLicenceNo" + _objectId).val();
            busiLicence.expDate = $("#modify_expDate" + _objectId).val();
            busiLicence.busiLicencePic = $("#img" + _objectId).attr("src").replace(getUrlImg(), "");
            return busiLicence;
        },
        /**
         * 更新营业执照
         */
        doUpdateBusiLicence: function() {
            var self = this;
            var busiLicencelist = new Array();
            busiLicencelist.push(self.getBusiLicenceObj("1", ""));
            busiLicencelist.push(self.getBusiLicenceObj("2", "_sp"));
            busiLicencelist.push(self.getBusiLicenceObj("3", "_ws"));
            if ($("#modify_tags").find("option:selected").text() == "超市" || $("#modify_tags").find("option:selected").text() == "烟酒") {
                busiLicencelist.push(self.getBusiLicenceObj("4", "_yc"));
                busiLicencelist.push(self.getBusiLicenceObj("5", "_jl"));
            }

            $.ajax({
                "type": 'POST',
                "url": CRM.getOuterUrl('/shop/licence/createShopBusiLicence'),
                "dataType": "json",
                async: true, //请求是否异步，默认为异步，这也是ajax重要特性
                contentType: "application/json",
                xhrFields: {
                    withCredentials: true
                },
                "data": JSON.stringify({
                    shopId: $("#modify_shopId").val(),
                    userId: $("#modify_userId").val(),
                    operator: $.cookie('_uk'),
                    reqList: busiLicencelist
                }),
                contentType: "application/json",
                "success": function(req) {
                    //CRM.showDialog(req.message);
                },
                error: function(e) {
                    //请求出错处理
                    CRM.showDialog("操作营业执照,请求服务异常！");
                }
            });
        },
        /**
         * 店铺下线
         * @param shopId
         */
        shopSuspension: function(shopId) {
            var self = this;
            $('#comfirm').unbind("click");
            $("#comfirm").on('click', function() {
                $('#confirm_dialog').modal('hide');
                $.ajax({
                    "type": 'POST',
                    "url": CRM.getOuterUrl('/shop/shop/shopSuspension'),
                    "dataType": "json",
                    async: true, //请求是否异步，默认为异步，这也是ajax重要特性
                    contentType: "application/json",
                    xhrFields: {
                        withCredentials: true
                    },
                    "data": JSON.stringify({
                        id: shopId,
                        operator: $.cookie('_uk')
                    }),
                    contentType: "application/json",
                    "success": function(req) {
                        $("#msg_dialog_content").text(req.message);
                        $('#msg_dialog').modal('show');

                        $('#shop_table').DataTable().ajax.reload();
                    },
                    error: function(e) {
                        //请求出错处理
                        $("#msg_dialog_content").text("店铺下线,请求服务异常！");
                        $('#msg_dialog').modal('show');
                    }
                });
            });
            $("#confirm_dialog_content").text("确定要店铺下线？");
            $('#confirm_dialog').modal('show');
        },
        /**
         * 暂停或恢复营业
         * @param shopId
         * @param onsell
         */
        shopPauseOrOnSale: function(shopId, onsell) {
            if (onsell == 1) {
                onsell = 0
            } else {
                onsell = 1;
            }
            var self = this;
            $('#comfirm').unbind("click");
            $("#comfirm").on('click', function() {
                $('#confirm_dialog').modal('hide');
                CRM.request({
                    "type": 'POST',
                    "url": CRM.getOuterUrl('/shop/shop/updateShopForXiaoer'),
                    "dataType": "json",
                    contentType: "application/json",
                    "data": JSON.stringify({
                        id: shopId,
                        onsell: onsell,
                        operator: $.cookie('_uk')
                    }),
                    "success": function(req) {
                        if (req.status) {
                            CRM.showDialog(req.message);
                            $('#shop_table').DataTable().ajax.reload();
                        } else {
                            CRM.showDialog(req.message);
                        }
                    }
                });
            });
            var confirmStr = "确定要暂停营业？";
            if (onsell == 1) {
                confirmStr = "确定要恢复营业？";
            }
            $("#confirm_dialog_content").text(confirmStr);
            $('#confirm_dialog').modal('show');
        },
        /**
         * 审核通过
         * @param shopId
         */
        auditShopSuccess: function(shopId) {
            $('#comfirm').unbind("click");
            $("#comfirm").on('click', function() {
                $('#confirm_dialog').modal('hide');
                $.ajax({
                    "type": 'POST',
                    "url": CRM.getOuterUrl('/shop/shop/auditShopSuccess'),
                    "dataType": "json",
                    async: true, //请求是否异步，默认为异步，这也是ajax重要特性
                    contentType: "application/json",
                    xhrFields: {
                        withCredentials: true
                    },
                    "data": JSON.stringify({
                        id: $("#modify_shopId").val(),
                        operator: $.cookie('_uk')
                    }),
                    contentType: "application/json",
                    "success": function(req) {
                        $('#shop_modify_dialog').modal('hide');
                        CRM.showDialog(req.message);
                        $('#shop_table').DataTable().ajax.reload();
                    },
                    error: function(e) {
                        //请求出错处理
                        CRM.showDialog("审核通过,请求服务异常！");
                    }
                });
            });
            $("#confirm_dialog_content").text("确定通过该审核？");
            $('#confirm_dialog').modal('show');
        },
        /**
         * 更新banner
         */
        updateBanner: function() {
            $("#sale_form").data('bootstrapValidator').resetForm();
            $("#sale_form").data('bootstrapValidator').validate();
            if ($("#sale_form").data('bootstrapValidator').isValid()) {
                var banner = "";
                $($("#sale_form").serializeArray()).each(function() {
                    if (this.value && this.name != "sale_shop_id") {
                        var _str = this.name.split("_");
                        banner += $("#sale_pic_img_" + _str[_str.length - 1]).attr("src") + "@!:" + this.value + "@!;";
                    }
                });
                CRM.request({
                    "type": 'POST',
                    "url": CRM.getOuterUrl('/shop/shop/updateShopForXiaoer'),
                    "dataType": "json",
                    contentType: "application/json",
                    "data": JSON.stringify({
                        id: $("#sale_shop_id").val(),
                        banner: banner,
                        operator: $.cookie('_uk')
                    }),
                    "success": function(req) {
                        if (req.status) {
                            CRM.showDialog(req.message);
                        } else {
                            CRM.showDialog(req.message);
                        }
                    }
                });
            }
        },
        /**
         * 审核不通过
         * @param shopId
         */
        auditShopFail: function(shopId) {
            $('#comfirm').unbind("click");
            $("#comfirm").on('click', function() {
                $('#confirm_dialog').modal('hide');
                $.ajax({
                    "type": 'POST',
                    "url": CRM.getOuterUrl('/shop/shop/auditShopFail'),
                    "dataType": "json",
                    async: true, //请求是否异步，默认为异步，这也是ajax重要特性
                    contentType: "application/json",
                    xhrFields: {
                        withCredentials: true
                    },
                    "data": JSON.stringify({
                        id: $("#modify_shopId").val(),
                        operator: $.cookie('_uk')
                    }),
                    contentType: "application/json",
                    "success": function(req) {
                        $('#shop_modify_dialog').modal('hide');
                        $("#msg_dialog_content").text(req.message);
                        $('#msg_dialog').modal('show');
                        $('#shop_table').DataTable().ajax.reload();
                    },
                    error: function(e) {
                        //请求出错处理
                        $("#msg_dialog_content").text("审核不通过,请求服务异常！");
                        $('#msg_dialog').modal('show');
                    }
                });
            });
            $("#confirm_dialog_content").text("确定不通过该审核？");
            $('#confirm_dialog').modal('show');
        },
        /**
         * 文件上传组件初始化
         */
        initUpload: function() {
            $("#modify_socialImage_file").fileupload({
                url: CRM.getOuterUrl('/itemcenter/upload/server'), //文件上传地址，当然也可以直接写在input的data-url属性内
                //formData:{param1:"p1",param2:"p2"},//如果需要额外添加参数可以在这里添加
                done: function(e, req) {
                    //done方法就是上传完毕的回调函数，其他回调函数可以自行查看api
                    //注意result要和jquery的ajax的data参数区分，这个对象包含了整个请求信息
                    //返回的数据在result.result中，假设我们服务器返回了一个json对象
                    if (req.result.status) {
                        if (req.result.entry) {
                            $("#modify_socialImage").attr("src", getUrlImg() + req.result.entry);
                        }
                    } else {
                        $("#msg_dialog_content").text(req.result.message);
                        $('#msg_dialog').modal('show');
                    }

                }
            });
            $("#modify_socialImageBack_file").fileupload({
                url: CRM.getOuterUrl('/itemcenter/upload/server'), //文件上传地址，当然也可以直接写在input的data-url属性内
                //formData:{param1:"p1",param2:"p2"},//如果需要额外添加参数可以在这里添加
                done: function(e, req) {
                    //done方法就是上传完毕的回调函数，其他回调函数可以自行查看api
                    //注意result要和jquery的ajax的data参数区分，这个对象包含了整个请求信息
                    //返回的数据在result.result中，假设我们服务器返回了一个json对象
                    if (req.result.status) {
                        if (req.result.entry) {
                            $("#modify_socialImageBack").attr("src", getUrlImg() + req.result.entry);
                        }
                    } else {
                        $("#msg_dialog_content").text(req.result.message);
                        $('#msg_dialog').modal('show');
                    }

                }
            });
            $("#img_file").fileupload({
                url: CRM.getOuterUrl('/itemcenter/upload/server'), //文件上传地址，当然也可以直接写在input的data-url属性内
                //formData:{param1:"p1",param2:"p2"},//如果需要额外添加参数可以在这里添加
                done: function(e, req) {
                    //done方法就是上传完毕的回调函数，其他回调函数可以自行查看api
                    //注意result要和jquery的ajax的data参数区分，这个对象包含了整个请求信息
                    //返回的数据在result.result中，假设我们服务器返回了一个json对象
                    if (req.result.status) {
                        if (req.result.entry) {
                            $("#img").attr("src", getUrlImg() + req.result.entry);
                        }
                    } else {
                        $("#msg_dialog_content").text(req.result.message);
                        $('#msg_dialog').modal('show');
                    }

                }
            });
            $("#img_sp_file").fileupload({
                url: CRM.getOuterUrl('/itemcenter/upload/server'), //文件上传地址，当然也可以直接写在input的data-url属性内
                //formData:{param1:"p1",param2:"p2"},//如果需要额外添加参数可以在这里添加
                done: function(e, req) {
                    //done方法就是上传完毕的回调函数，其他回调函数可以自行查看api
                    //注意result要和jquery的ajax的data参数区分，这个对象包含了整个请求信息
                    //返回的数据在result.result中，假设我们服务器返回了一个json对象
                    if (req.result.status) {
                        if (req.result.entry) {
                            $("#img_sp").attr("src", getUrlImg() + req.result.entry);
                        }
                    } else {
                        $("#msg_dialog_content").text(req.result.message);
                        $('#msg_dialog').modal('show');
                    }

                }
            });
            $("#img_ws_file").fileupload({
                url: CRM.getOuterUrl('/itemcenter/upload/server'), //文件上传地址，当然也可以直接写在input的data-url属性内
                //formData:{param1:"p1",param2:"p2"},//如果需要额外添加参数可以在这里添加
                done: function(e, req) {
                    //done方法就是上传完毕的回调函数，其他回调函数可以自行查看api
                    //注意result要和jquery的ajax的data参数区分，这个对象包含了整个请求信息
                    //返回的数据在result.result中，假设我们服务器返回了一个json对象
                    if (req.result.status) {
                        if (req.result.entry) {
                            $("#img_ws").attr("src", getUrlImg() + req.result.entry);
                        }
                    } else {
                        $("#msg_dialog_content").text(req.result.message);
                        $('#msg_dialog').modal('show');
                    }

                }
            });
            $("#img_yc_file").fileupload({
                url: CRM.getOuterUrl('/itemcenter/upload/server'), //文件上传地址，当然也可以直接写在input的data-url属性内
                //formData:{param1:"p1",param2:"p2"},//如果需要额外添加参数可以在这里添加
                done: function(e, req) {
                    //done方法就是上传完毕的回调函数，其他回调函数可以自行查看api
                    //注意result要和jquery的ajax的data参数区分，这个对象包含了整个请求信息
                    //返回的数据在result.result中，假设我们服务器返回了一个json对象
                    if (req.result.status) {
                        if (req.result.entry) {
                            $("#img_yc").attr("src", getUrlImg() + req.result.entry);
                        }
                    } else {
                        $("#msg_dialog_content").text(req.result.message);
                        $('#msg_dialog').modal('show');
                    }

                }
            });
            $("#img_jl_file").fileupload({
                url: CRM.getOuterUrl('/itemcenter/upload/server'), //文件上传地址，当然也可以直接写在input的data-url属性内
                //formData:{param1:"p1",param2:"p2"},//如果需要额外添加参数可以在这里添加
                done: function(e, req) {
                    //done方法就是上传完毕的回调函数，其他回调函数可以自行查看api
                    //注意result要和jquery的ajax的data参数区分，这个对象包含了整个请求信息
                    //返回的数据在result.result中，假设我们服务器返回了一个json对象
                    if (req.result.status) {
                        if (req.result.entry) {
                            $("#img_jl").attr("src", getUrlImg() + req.result.entry);
                        }
                    } else {
                        $("#msg_dialog_content").text(req.result.message);
                        $('#msg_dialog').modal('show');
                    }

                }
            });
            $("input[id^='sale_pic_file_']").fileupload({
                url: CRM.getOuterUrl('/itemcenter/upload/server'), //文件上传地址，当然也可以直接写在input的data-url属性内
                //formData:{param1:"p1",param2:"p2"},//如果需要额外添加参数可以在这里添加
                done: function(e, req) {
                    //done方法就是上传完毕的回调函数，其他回调函数可以自行查看api
                    //注意result要和jquery的ajax的data参数区分，这个对象包含了整个请求信息
                    //返回的数据在result.result中，假设我们服务器返回了一个json对象
                    if (req.result.status) {
                        if (req.result.entry) {
                            $("#" + this.id).parent().parent().find("img").attr("src", getUrlImg() + req.result.entry);
                        }
                    } else {
                        CRM.showDialog(req.result.message);
                    }

                }
            });
        },
        /**
         * 查询店铺收款账户信息
         * @param shopId
         * @param receiptAccountType
         */
        queryShopReceiptsAccount: function(shopId, receiptAccountType) {
            var self = this;
            $.ajax({
                "type": 'POST',
                "url": CRM.getOuterUrl('/shop/account/queryShopReceiptsAccount'),
                "dataType": "json",
                async: true, //请求是否异步，默认为异步，这也是ajax重要特性
                contentType: "application/json",
                xhrFields: {
                    withCredentials: true
                },
                "data": JSON.stringify({
                    shopId: shopId,
                    receiptAccountType: receiptAccountType,
                    operator: $.cookie('_uk')
                }),
                contentType: "application/json",
                "success": function(req) {
                    if (req.status) {
                        if (req.entry) {
                            if (receiptAccountType == 1) {
                                $("#cardPic").attr("src", getUrlImg() + req.entry.cardPic);
                                $("#modify_cardName").val(req.entry.accountName);
                                $("#modify_cardNum").val(req.entry.accountNO);
                                self.queryShopReceiptsAccount(shopId, 2);
                            } else {
                                $("#zhifubao_cardName").val(req.entry.accountName);
                                $("#zhifubao_cardNum").val(req.entry.accountNO);
                            }
                        }
                    } else {
                        $("#msg_dialog_content").text(req.message);
                        $('#msg_dialog').modal('show');
                    }
                },
                error: function(e) {
                    //请求出错处理
                    $("#msg_dialog_content").text("查询店铺收款账户信息,请求服务异常！");
                    $('#msg_dialog').modal('show');
                }
            });
        },
        /**
         * 手机号码获取用户信息
         * @param mobile
         */
        getUserInfo: function(mobile) {
            var _userId;
            CRM.request({
                url: CRM.getOuterUrl('/member/getUserbyMobile.do?mobile=' + mobile),
                type: 'get',
                async: false,
                success: function(data) {
                    if (data.status) {
                        _userId = data.entry.userId;
                    }
                }
            });
            return _userId;
        },
        bindEvent: function() {
            var self = this;
            $("#search_btn").on('click', function() {
                self.doSearch();
            });
            $("#modifyShop").on('click', function() {
                self.doUpdate(true);
            });
            $("#push_modify").on('click', function() {
                self.doUpdate(false);
            });
            $("#push_audit").on('click', function() {
                self.submitToAudit(true);
            });
            $("#pass").on('click', function() {
                self.auditShopSuccess();
            });
            $("#not_pass").on('click', function() {
                self.auditShopFail();
            });
            $("#changeShopOwner").on('click', function() {
                self.changeShopOwner();
            });
            $("#search_type").on('change', function() {
                $("#shop_name").attr("placeholder", $("#search_type").find("option:selected").text());
            });
            $("#shopSale").on('click', function() {
                self.updateBanner();
            });
        }
    };

    /**
     * 图片上传的
     * @returns {*}
     */
    function getUrlImg() {
        // 日常环境
        if (!!~location.host.indexOf('daily.')) {
            //return 'http://imgdaily.52shangou.com/img/';
            return 'http://imgsize.52shangou.com/img/'
        }
        // 线上环境 & 灰度环境
        else {
            return 'http://imgsize.52shangou.com/img/'
        }
    }

    window.changeShopOwner = Config.changeShopOwner;
    window.doSearch = $.proxy(Config.doSearch, Config);
    window.editShop = $.proxy(Config.editShop, Config);
    window.deleteShop = $.proxy(Config.deleteShop, Config);
    window.modifyShop = $.proxy(Config.modifyShop, Config);
    window.auditShop = $.proxy(Config.auditShop, Config);
    window.shopSuspension = $.proxy(Config.shopSuspension, Config);
    window.shopCouponSwitch = $.proxy(Config.shopCouponSwitch, Config);
    window.shopPauseOrOnSale = $.proxy(Config.shopPauseOrOnSale, Config);
    window.modifyShopSale = $.proxy(Config.modifyShopSale, Config);
    window.queryOrders = $.proxy(Config.queryOrders, Config);


    Config.init();
});
